package com.mtsmda.is.admin.domain;

import static com.mtsmda.is.admin.domain.util.db.ConstantsDB.*;

public class AttrValue {

	private Integer attrValueId;
	private Attribute attribute;
	private String attrValueName;
	private String attrValueDescription;

	public AttrValue() {
		super();
	}

	public AttrValue(String attrValueName, String attrValueDescription) {
		this();
		setAttrValueName(attrValueName);
		setAttrValueDescription(attrValueDescription);
	}

	public Integer getAttrValueId() {
		return attrValueId;
	}

	public void setAttrValueId(Integer attrValueId) {
		this.attrValueId = attrValueId;
	}

	public Attribute getAttribute() {
		return attribute;
	}

	public void setAttribute(Attribute attribute) {
		this.attribute = attribute;
	}

	public String getAttrValueName() {
		return attrValueName;
	}

	public void setAttrValueName(String attrValueName) {
		if (attrValueName.length() > LENGTH_FIELD_250) {
			this.attrValueName = attrValueName.substring(0, LENGTH_FIELD_250);
		} else {
			this.attrValueName = attrValueName;
		}
	}

	public String getAttrValueDescription() {
		return attrValueDescription;
	}

	public void setAttrValueDescription(String attrValueDescription) {
		if (attrValueDescription.length() > LENGTH_FIELD_500) {
			this.attrValueDescription = attrValueDescription.substring(0,
					LENGTH_FIELD_500);
		} else {
			this.attrValueDescription = attrValueDescription;
		}
	}

	@Override
	public String toString() {
		return "AttrValue [attrValueId=" + attrValueId + ", attribute="
				+ attribute + ", attrValueName=" + attrValueName
				+ ", attrValueDescription=" + attrValueDescription + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof AttrValue && obj != null) {
			AttrValue attrValue = (AttrValue) obj;
			if (attrValue.getAttribute().equals(this.getAttribute())
					&& attrValue.getAttrValueDescription().equals(
							this.getAttrValueDescription())
					&& attrValue.getAttrValueId().equals(this.getAttrValueId())
					&& attrValue.getAttrValueName().equals(
							this.getAttrValueName())) {
				return true;
			}
			if (attrValue == this) {
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hashCode = this.getAttrValueId().hashCode() * 3;
		hashCode += this.getAttribute().hashCode() * 17;
		hashCode += this.getAttrValueDescription().hashCode() * 5;
		hashCode += this.getAttrValueName().hashCode() * 7;
		return hashCode;
	}

}